package com.usian.wemedia.controller;

import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.dtos.WmMaterialDto;
import com.usian.model.media.pojos.WmMaterial;
import com.usian.wemedia.WmMaterialControllerApi;
import com.usian.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController implements WmMaterialControllerApi {


    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 上传素材库图片接口
     *
     * @param file
     * @return
     */
    @Override
    @PostMapping("/upload_picture")
    public ResponseResult uploadPic(MultipartFile file) {
        return wmMaterialService.uploadPic(file);
    }

    /**
     * 查询素材列表
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDto dto) {
        return wmMaterialService.list(dto);
    }

    /**
     * 删除素材库图片
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPic(@PathVariable Integer id) {
        return wmMaterialService.delPic(id);
    }

    /**
     * 收藏图片
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/collect/{id}")
    public ResponseResult cancleCollectionMaterial(@PathVariable Integer id) {
        return wmMaterialService.updateStatus(id, (short)1);
    }

    /**
     * 取消收藏图片
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult collectionMaterial(@PathVariable Integer id) {
        return wmMaterialService.updateStatus(id, (short)0);
    }
}
